<?php
namespace app\admin\controller;

use app\admin\service\Admin;
use app\exceptions\OrdinaryException;

class Login extends Controllers
{

    public function login()
    {
        $get = $this->request->get();
        if ( session('token') && (!isset($get['type']) || $get['type'] !== 'switch') ) {
            return redirect('/admin');
        }
        return view('admin@login/login');
    }

    /**
     * 登录提交
     * @throws OrdinaryException
     */
    public function input( Admin $admin )
    {
        $post = $this->request->only(['username','password','captcha','online'], 'post');
        $this->validate($post,'app\admin\validate\Admin.login');
        return $admin->login($post);
    }

    public function logout( Admin $admin )
    {
        return $admin->logout();
    }
}